//
//  ViewController.m
//  04-UIControl
//
//  Created by 李昊林 on 16/7/19.
//  Copyright © 2016年 李昊林. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    //UISwitch 开关
    //switch的宽高不影响控件只有x，y有关
    UISwitch *switch1 = [[UISwitch alloc]initWithFrame:CGRectMake(100, 100, 1000, 1000)];
    [self.view addSubview:switch1];
    //开启控件时候的内部颜色设置
    switch1.onTintColor = [UIColor redColor];
    //边框以及切换到关闭时的颜色 =nil时候为灰色 （null_ressetable）
    switch1.tintColor = [UIColor blackColor];
    //开关按钮（圆圈）的颜色
    switch1.thumbTintColor = [UIColor blueColor];
    //打开时的图片，iOS7后失效
    switch1.onImage = [UIImage imageNamed:@"welcome_2.jpg"];
    //关闭时的图片，iOS7后失效
    switch1.offImage = [UIImage imageNamed:@"welcome_2.jpg"];
    //判断switchControl的开闭状态 no 关闭 yes开启、
    //通过set方法改变switch的初始方法
    switch1.on = YES;
    NSLog(@"%@",switch1.isOn ? @"YES" : @"NO");
    [switch1 setOn:YES animated:YES];
    //添加绑定事件(与button相同)
    [switch1 addTarget:self action:@selector(switchAction:) forControlEvents:UIControlEventValueChanged];
    

    //UISlider
    //slider的高度不影响控件的高度，这个控件永远居中与视图中间
    UISlider *Slider1 = [[UISlider alloc] initWithFrame:CGRectMake(10, 200, 355, 50)];
    [self.view addSubview:Slider1];
    Slider1.backgroundColor = [UIColor yellowColor];
    //未移动的区域颜色
    Slider1.minimumTrackTintColor = [UIColor blueColor];
    //已移动的区域颜色
    Slider1.maximumTrackTintColor = [UIColor greenColor];
    //按钮的颜色
    Slider1.thumbTintColor = [UIColor blackColor];
    //已移动方向的图片
    [Slider1 setMaximumTrackImage:[UIImage imageNamed:@"player_slider_playback_right"] forState:UIControlStateNormal];
    [Slider1 setMinimumTrackImage:[UIImage imageNamed:@"player_slider_playback_left"] forState:UIControlStateNormal];
    
    
    Slider1.minimumValueImage = [UIImage imageNamed:@""];
    //未移动方向的图片
    Slider1.maximumValueImage = [UIImage imageNamed:@""];
//当前划块的值
    Slider1.value = 0.5f;
    //最小值
    Slider1.minimumValue = 0.0f;
    //最大值
    Slider1.maximumValue = 1.0f;
    //以上最大最小值可以根据需求而改变
    
    Slider1.continuous = YES;
    //
    [Slider1 addTarget:self action:@selector(sliderAction:) forControlEvents:UIControlEventValueChanged];
    
    
    //UIsegmente
    UISegmentedControl *segment = [[UISegmentedControl alloc] initWithItems:@[@"first", @"second", @"ddd"]];
    segment.frame = CGRectMake(20, 400, 350, 30);
    // 如果不给frame,系统会自动计算大小,
    NSLog(@"%@", NSStringFromCGRect(segment.frame));
    // 1.momentary 设置为YES,如果点击选中没有选中的效果
    segment.momentary = YES;
    segment.tag = 1000;
    NSInteger numberOfSegment = segment.numberOfSegments;
    NSLog(@"分段控制器item的个数是%ld", numberOfSegment);
    
    [self.view addSubview:segment];
    
    
    // 点击Button, 给segment添加新的标题
    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
    button.frame = CGRectMake(20, 440, 140, 40);
    [self.view addSubview:button];
    button.backgroundColor = [UIColor yellowColor];
    [button addTarget:self action:@selector(addSegmentTitle:) forControlEvents:UIControlEventTouchUpInside];
    // 3. insertSegmentWithTitle:@"sss" atIndex:1 animated:YES
    // 4. remove
    // 5.     setTitle:<#(nullable NSString *)#> forSegmentAtIndex:<#(NSUInteger)#>
    [segment setTitle:@"iii" forSegmentAtIndex:0];
    // 默认是0.0
    [segment setWidth:90 forSegmentAtIndex:0];
    // 6.  - (void)setWidth:(CGFloat)width forSegmentAtIndex:(NSUInteger)segment;  设置个别item的宽度
    //7.etContentOffset: forSegmentAtIndex:设置对应下标内容的偏移
    [segment setContentOffset:CGSizeMake(0, 20) forSegmentAtIndex:0];
    [segment setWidth:0 forSegmentAtIndex:1];
    //8.setEnabled:forSegmentAtIndex:
    [segment setEnabled:NO forSegmentAtIndex:2];
    [self.view addSubview:segment];
    //9.selectedSegmentIndex选中下标
    segment.selectedSegmentIndex = 1;
    //10.tintColor文字及边框颜色
    segment.tintColor = [UIColor purpleColor];
    //11.apportionsSegmentWidthsByContent默认为NO
    //如果分段控制器带宽设置为0时，并且该属性为YES，系统会自动计算
    segment.apportionsSegmentWidthsByContent = YES;
    //12.segment绑定事件
//    [segment addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventValueChanged];
    
    //UIPageControl
    UIPageControl *page = [[UIPageControl alloc] initWithFrame:CGRectMake(20, 250, 250, 50)];
    page.backgroundColor = [UIColor blackColor];
    //分页控制器的页数 默认为0
    page.numberOfPages = 5;
    //当前页
    page.currentPage = 3;
    //隐藏页面
    //page.hidesForSinglePage = YES;
    //
    CGSize size = [page sizeForNumberOfPages:1];
    NSLog(@"%@",NSStringFromCGSize(size));
    //
    page.tintColor = [UIColor grayColor];
    //当前页的颜色
    page.currentPageIndicatorTintColor = [UIColor purpleColor];
    [self.view addSubview:page];
    
    //
    [page addTarget:self action:@selector(pageChange:) forControlEvents:UIControlEventValueChanged];
    //8.关闭系统事件配置的切换，直到
    page.defersCurrentPageDisplay = YES;

    
    
    
    
}

- (void)pageChange:(UIPageControl *)page {
    NSLog(@"change");
}






//- (void)segmentAction:(UISegmentedControl *)segment {
//    switch (segment.selectedSegmentIndex) {
//        case 0:
//            
//            break;
//        case 1:
//            
//            break;
//        case 2:
//            
//            break;
//        default:
//            break;
//    }

- (void)addSegmentTitle:(UIButton *)button{
    UISegmentedControl *segment = [self.view viewWithTag:1000];
    [segment insertSegmentWithTitle:@"sss" atIndex:1 animated:YES];
}

- (void)sliderAction:(UISlider *)sliderControl{
    NSLog(@"%f", sliderControl.value);
}

//switch触发事件
- (void)switchAction:(UISwitch *)switch1 {
//根据switch的状态，决定触发什么事件
    if (switch1.on == YES) {
        NSLog(@"开");
    } else {
        NSLog(@"关");
    }
    
//    NSLog(@"开关事件");
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
